import { instance } from '../request'

const request = instance

/**
 * 获取分类列表
 *
 * @return s
 */
export const getSortListApi = (): PromiseRes<SortItf[]> =>
  request.get('/sort/getSortList')

/**
 * 创建子分类
 * @param description 分类描述
 * @param parentId  分类上级id
 * @param weight 分类优先级，可选
 * @returns
 */
export const createSortApi = (
  description: string,
  parentId: string,
  weight?: number
): PromiseRes =>
  request.post(`/sort/createSort`, { description, parentId, weight })

/**
 * 修改分类信息
 * @param description  分类描述
 * @param sortId 分类id
 * @param weight 分类优先级，可选
 * @returns
 */
export const updateSortApi = (
  description: string,
  sortId: string,
  weight?: number
): PromiseRes =>
  request.post(`/sort/updateSort?sortId=${sortId}`, { description, weight })

/**
 * 批量删除分类
 *
 * @param sortIdList 分类id列表
 * @return
 */
export const deleteSortApi = (sortIdList: string[]): PromiseRes =>
  request.post(`/sort/deleteSorts`, sortIdList)
